<template>
	<view class="all">
		<view class="list">
			<u-empty v-show="!show" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">
			</u-empty>
			<view v-show="show" class="box flex_sp" v-for="(item , index) in list" :key="index"
				@click="back(item.id,item.bank)">
				<view class="left">
					<view class="top">
						{{item.bank}}
					</view>
					<view class="bot">
						{{item.card_number}}
					</view>
				</view>
				<view class="right">
					<image src="../../../static/ming/two.png" mode="" @click="bianji(item.id)"></image>
					<image src="../../../static/ming/one.png" mode="" @click="dele(item.id)"></image>
				</view>
			</view>
		</view>
		<view class="last">
			<image src="../../../static/ming/three.png" mode="" @click="addbank()"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				show: false,
				info: ""
			};
		},
		onLoad(option) {
			if (option.info) {
				this.info = option.info
			}
		},
		onShow() {
			this.getbank()
		},
		methods: {
			back(id, name) {
				if (this.info) {
					uni.$emit("upid", {
						id,
						name
					})
					uni.navigateBack({
						delta: 1
					})
				}
			},
			async getbank() {
				const res = await this.$api('/business/user/bank', 'post').then((res) => {
					console.log(res);
					if (res.data.code == 1) {
						this.list = res.data.data
						if (res.data.data.length == 0) {
							this.show = true
						} else {
							this.show = true
						}
					}
				})
			},
			bianji(i) {
				console.log("编辑");
				uni.navigateTo({
					url: '/pages/mine/addbank/addbank?id=' + i
				})
			},
			dele(i) {
				const that = this
				uni.showModal({
					content: "确定删除该银行卡嘛",
					success(res) {
						console.log(res)
						if (res.confirm) {
							that.$api("/business/user/del_bank", 'post', {
								id: i
							}).then((res) => {
								console.log(res);
								if (res.data.code == 1) {
									uni.$u.toast(res.data.msg)
									that.getbank()
								}
							})

						} else {
							console.log("我是取消");
						}
					}
				})
			},
			addbank() {
				uni.navigateTo({
					url: '/pages/mine/addbank/addbank'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.all {
		padding: 15px;
		background-color: #f5f5f5;
		min-height: 100vh;

		.list {
			.box {
				background: #FFFFFF;
				border-radius: 10px;
				padding: 10px;
				margin: 10px 0;

				.left {
					.top {
						font-size: 14px;
						font-weight: bold;
						color: #333333;
						margin: 5px 0;
					}

					.bot {
						margin: 5px 0;
						font-size: 14px;
						font-weight: bold;
						color: #333333;
					}
				}

				.right {
					image {
						width: 18px;
						height: 18px;
						margin: 0 10px;
					}
				}

			}
		}

		.last {
			background: #FFFFFF;
			border-radius: 10px;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 15px 0;

			image {
				width: 18px;
				height: 18px;
			}
		}
	}
</style>